package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.SlpPageDto;
import org.rc.entity.Slp;
import org.rc.mapper.SlpMapper;
import org.rc.service.SlpService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SlpServiceImpl extends ServiceImpl<SlpMapper, Slp> implements SlpService {
    @Override
    public void addSlp(Slp slp) {
        this.save(slp);
    }

    @Override
    public Page<Slp> getSlpPage(SlpPageDto slpPageDto) {
        Page<Slp> page = new Page<>(slpPageDto.getPageNo(),slpPageDto.getPageSize());
        QueryWrapper<Slp> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(slpPageDto.getName()),"name",slpPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public void updateSlp(Slp slp) {
        this.updateById(slp);
    }

    @Override
    public void deleteSLp(Long id) {
        this.removeById(id);
    }

    @Override
    public void batchDeleteSlp(List<Long> ids) {
        this.removeByIds(ids);
    }

    @Override
    public List<Slp> getAllSlp() {
        return list();
    }

    @Override
    public Slp getSlpByMac(String mac) {
        QueryWrapper<Slp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mac",mac);
        return this.getOne(queryWrapper);
    }
}
